//
//  OrderDetailViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/6.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "OrderDetailViewController.h"
#import <AlipaySDK/AlipaySDK.h>
#import "MoreDetailViewController.h"
#import "LogisticsMessageViewController.h"
#import "PayViewController.h"
#import "ShareURLView.h"

@interface OrderDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UIButton *left1Btn;
@property (nonatomic, strong) UIButton *left2Btn;
@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) ShareURLView    *shareUrlView;


@end

@implementation OrderDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    self.view.backgroundColor = RGB_COLOR(244, 244, 244);
    
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49)) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    [self setBottomBar];
//    [self getData];
}

//- (void)getData {
//    NSString *url = [NSString stringWithFormat:@"%@api/getUserOrderDetail",REQUESTHEADER];
//    NSDictionary *dict = @{@"ordId":_ordId};
//    [HttpManager postHttpRequestByGet:url andParameter:dict success:^(id successResponse) {
//        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
//        if ([status isEqualToString:@"200"]) {
//            NSError *error;
//            OrderModel *model = [[OrderModel alloc] initWithDictionary:successResponse[@"data"][@"orderInfo"] error:&error];
//            self.model = model;
//            [self.tableView reloadData];
//        }else{
//            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
//        }
//    } andFailure:^(id failureResponse) {
//        [HttpManager showFail];
//    }];
//}

- (void)setBottomBar {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49), SCREEN_WIDTH, ScreenX375(49))];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.shadowColor = RGBACOLOR(0, 0, 0, 0.07).CGColor;
    view.layer.shadowOffset = CGSizeMake(0, -1);
    view.layer.shadowOpacity = 1;
    view.layer.shadowRadius = 4;
    [self.view addSubview:view];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
    line.backgroundColor = REXADECIMALCOLOR(@"#ededed");
    [view addSubview:line];
    
    self.left1Btn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(291), ScreenX375(9), ScreenX375(84), ScreenX375(32))];
    [self.left1Btn setTitle:@"联系客服" forState:UIControlStateNormal];
    [self.left1Btn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    self.left1Btn.layer.borderColor = REXADECIMALCOLOR(@"#f0f0f0").CGColor;
    self.left1Btn.layer.borderWidth = 1;
    self.left1Btn.clipsToBounds = YES;
    self.left1Btn.titleLabel.font = Kfont(13);
    self.left1Btn.layer.cornerRadius = ScreenX375(16);
    [self.left1Btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.left1Btn];
    
    self.left2Btn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32))];
    [self.left2Btn setTitle:@"查看物流" forState:UIControlStateNormal];
    [self.left2Btn setTitleColor:FONTCOLOR_BLACK forState:UIControlStateNormal];
    self.left2Btn.layer.borderColor = REXADECIMALCOLOR(@"#f0f0f0").CGColor;
    self.left2Btn.layer.borderWidth = 1;
    self.left2Btn.clipsToBounds = YES;
    self.left2Btn.titleLabel.font = Kfont(13);
    self.left2Btn.layer.cornerRadius = ScreenX375(16);
    [self.left2Btn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.left2Btn];
    
    self.rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32))];
    [self.rightBtn setTitle:@"立即付款" forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:REXADECIMALCOLOR(@"#ffffff") forState:UIControlStateNormal];
    [self.rightBtn setBackgroundImage:ImageWithName(@"按钮背景") forState:UIControlStateNormal];
    self.rightBtn.clipsToBounds = YES;
    self.rightBtn.titleLabel.font = Kfont(13);
    self.rightBtn.layer.cornerRadius = ScreenX375(16);
    [self.rightBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:self.rightBtn];
    
    switch ([_status integerValue]) {
        case 0:
            [self.rightBtn setTitle:@"立即付款" forState:UIControlStateNormal];
            self.left1Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.rightBtn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.left2Btn.hidden = YES;
            self.rightBtn.hidden = NO;
            break;
        case 1:
            [self.left2Btn setTitle:@"提醒发货" forState:UIControlStateNormal];
            self.left1Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.left2Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.left2Btn.hidden = NO;
            self.rightBtn.hidden = YES;
            break;
        case 2:
            [self.left2Btn setTitle:@"查看物流" forState:UIControlStateNormal];
            [self.rightBtn setTitle:@"确认收货" forState:UIControlStateNormal];
            self.left1Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(291), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.left2Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.rightBtn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32));
            self.left2Btn.hidden = NO;
            self.rightBtn.hidden = NO;
            break;
        case 5:
            if ([_model.proStatus integerValue] == 0) {
                [self.left2Btn setTitle:@"查看链接" forState:UIControlStateNormal];
                self.left1Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32));
                self.left2Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32));
                self.left2Btn.hidden = NO;
                self.rightBtn.hidden = YES;
            }else {
                [self.left2Btn setTitle:@"查看物流" forState:UIControlStateNormal];
                [self.rightBtn setTitle:@"购买" forState:UIControlStateNormal];
                self.left1Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(291), ScreenX375(9), ScreenX375(84), ScreenX375(32));
                self.left2Btn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(195), ScreenX375(9), ScreenX375(84), ScreenX375(32));
                self.rightBtn.frame = CGRectMake(SCREEN_WIDTH - ScreenX375(100), ScreenX375(9), ScreenX375(84), ScreenX375(32));
                self.left2Btn.hidden = NO;
                self.rightBtn.hidden = NO;
            }
            break;
            
        default:
            break;
    }
}

- (void)buttonAction:(UIButton *)button {
    if ([button.titleLabel.text isEqualToString:@"联系客服"]) {
        
    }else if ([button.titleLabel.text isEqualToString:@"查看物流"]) {
        LogisticsMessageViewController *vc = [[LogisticsMessageViewController alloc] init];
        vc.acceptAdress = [NSString stringWithFormat:@"%@%@%@  %@  %@",_model.recProvince,_model.recCity,_model.recArea,_model.recName,_model.recAddress];
        vc.orderNum =_model.ordNum;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([button.titleLabel.text isEqualToString:@"购买"]) {
        MoreDetailViewController *vc = [[MoreDetailViewController alloc] init];
        vc.proId = _model.Id;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([button.titleLabel.text isEqualToString:@"立即付款"]) {
        PayViewController *vc = [[PayViewController alloc] init];
        vc.picUrl = _model.proPic;
        vc.proName = _model.proName;
        vc.price = _model.proPrice;
        vc.ordNum = _model.ordNum;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([button.titleLabel.text isEqualToString:@"确认收货"]) {
        NSString * url = [NSString stringWithFormat:@"%@api/confirm",REQUESTHEADER];
        NSDictionary * parameter = @{@"userId":kNSUDefaultReadKey(@"userId"),@"ordNum":_model.ordNum};
        [HttpManager showWait];
        [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
            [HttpManager hideWait];
            NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
            if ([status isEqualToString:@"200"]) {
                [HttpManager showNoteMsg:@"确认收货成功"];
            }else{
                [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
            }
        } andFailure:^(id failureResponse) {
            [HttpManager showFail];
        }];
    }else if ([button.titleLabel.text isEqualToString:@"查看链接"]) {
        [self setShareURLView];
        [self.shareUrlView setUrl:_model.link andPassword:_model.downloadPassword];
    }else if ([button.titleLabel.text isEqualToString:@"提醒发货"]) {
        [HttpManager showNoteMsg:@"已提醒卖家发货"];
    }
}

-(void)setShareURLView{
    if (!_shareUrlView) {
        _shareUrlView = [[ShareURLView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    }
    [kKeyWindow addSubview:_shareUrlView];
    __weak __typeof(self) weakSelf = self;
    
    _shareUrlView.hiddenClick = ^{
        [weakSelf.shareUrlView removeFromSuperview];
    };
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return 2;
    }else if (section == 1) {
        return 3;
    }
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"stateCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
                
                UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, ScreenX375(60))];
                bgView.image = ImageWithName(@"按钮背景");
                [cell addSubview:bgView];
                
                UILabel *stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), 0, ScreenX375(150), ScreenX375(60))];
                switch ([_status integerValue]) {
                    case 0:
                        stateLabel.text = @"等待买家付款";
                        break;
                    case 1:
                        stateLabel.text = @"等待卖家发货";
                        break;
                    case 2:
                        stateLabel.text = @"卖家已发货";
                        break;
                    case 5:
                        if ([_model.proStatus integerValue] == 0) {
                            stateLabel.text = @"已完成";
                        }else {
                            stateLabel.text = @"买家已收货";
                        }
                        break;
                    default:
                        break;
                }
                stateLabel.textColor = REXADECIMALCOLOR(@"#ffffff");
                stateLabel.font = Kfont(20);
                [cell addSubview:stateLabel];
            }
            return cell;
        }else {
            static NSString *cellId = @"addressCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.subviews) {
                [subView removeFromSuperview];
            }
            if ([_status integerValue] >= 1 && [_model.status integerValue] && _model.recName) {
                UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(34), ScreenX375(16), ScreenX375(18))];
                icon.image = ImageWithName(@"定位-2");
                [cell addSubview:icon];
                
                UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(38), ScreenX375(14), ScreenX375(263), ScreenX375(17))];
                if (_model) {
                    nameLabel.text = [NSString stringWithFormat:@"收货人：%@",_model.recName];
                }
                nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
                nameLabel.font = Kfont(12);
                [cell addSubview:nameLabel];
                
                UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(174), ScreenX375(14), ScreenX375(150), ScreenX375(17))];
                if (_model) {
                    phoneLabel.text = _model.recPhone;
                }
                phoneLabel.textColor = REXADECIMALCOLOR(@"#333333");
                phoneLabel.font = Kfont(12);
                phoneLabel.textAlignment = NSTextAlignmentRight;
                [cell addSubview:phoneLabel];
                
                UILabel *addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(38), ScreenX375(41), ScreenX375(316), ScreenX375(35))];
                if (_model) {
                    addressLabel.text = [NSString stringWithFormat:@"收货地址：%@ %@ %@ %@",_model.recProvince,_model.recCity,_model.recArea,_model.recAddress];
                }
                addressLabel.textColor = REXADECIMALCOLOR(@"#333333");
                addressLabel.font = Kfont(12);
                addressLabel.numberOfLines = 0;
                [cell addSubview:addressLabel];
            }
            return cell;
        }
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            static NSString *cellId = @"personCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.subviews) {
                [subView removeFromSuperview];
            }
            UIImageView *headImage = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(11), ScreenX375(26), ScreenX375(26))];
            if (_model) {
                [headImage sd_setImageWithURL:[NSURL URLWithString:_model.proUserPic] placeholderImage:nil options:SDWebImageRetryFailed];
            }
            headImage.clipsToBounds = YES;
            headImage.layer.cornerRadius = ScreenX375(13);
            [cell addSubview:headImage];
            
            UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(52), ScreenX375(16), ScreenX375(263), ScreenX375(16))];
            if (_model) {
                nameLabel.text = _model.proUserName;
            }
            nameLabel.textColor = REXADECIMALCOLOR(@"#666666");
            nameLabel.font = Kfont(14);
            [cell addSubview:nameLabel];
            
            return cell;
        }else if (indexPath.row == 1) {
            static NSString *cellId = @"goodsCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.subviews) {
                [subView removeFromSuperview];
            }
            
            UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), 0, SCREEN_WIDTH - ScreenX375(32), 0.5)];
            line.backgroundColor = REXADECIMALCOLOR(@"#e4e4e4");
            [cell addSubview:line];
            
            UIImageView *goodsView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(12), ScreenX375(80), ScreenX375(80))];
            if (_model) {
                [goodsView sd_setImageWithURL:[NSURL URLWithString:_model.proPic] placeholderImage:nil options:SDWebImageRetryFailed];
            }
            goodsView.contentMode = UIViewContentModeScaleAspectFill;
            goodsView.clipsToBounds = YES;
            [cell addSubview:goodsView];
            
            UILabel *goodsName = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(11), ScreenX375(150), ScreenX375(17))];
            goodsName.textColor = REXADECIMALCOLOR(@"#212121");
            goodsName.font = Kfont(15);
            if (_model) {
                goodsName.text = _model.proName;
            }
            [cell addSubview:goodsName];
            
            UILabel *goodsNum = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(33), ScreenX375(150), ScreenX375(17))];
            goodsNum.textColor = REXADECIMALCOLOR(@"#212121");
            goodsNum.font = Kfont(15);
            if (_model) {
                goodsNum.text = [NSString stringWithFormat:@"x %@",_model.num];
            }
            [cell addSubview:goodsNum];
            
            UILabel *goodsPrice = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(106), ScreenX375(72), ScreenX375(150), ScreenX375(22))];
            goodsPrice.textColor = FONTCOLOR_BLACK;
            goodsPrice.font = Kfont(18);
            if (_model) {
                NSString *moneyStr = [NSString stringWithFormat:@"%.2f元",[_model.proPrice floatValue]];
                NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:moneyStr];
                [attributedStr addAttribute:NSForegroundColorAttributeName value:REXADECIMALCOLOR(@"#f21934") range:NSMakeRange(0, [moneyStr length] - 1)];
                goodsPrice.attributedText = attributedStr;
            }
            [cell addSubview:goodsPrice];
            return cell;
        }else {
            static NSString *cellId = @"detailCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            for (UIView *subView in cell.subviews) {
                [subView removeFromSuperview];
            }
            for (int i = 0; i < 3; i++) {
                UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), i * ScreenX375(46), SCREEN_WIDTH - ScreenX375(32), 0.5)];
                line.backgroundColor = REXADECIMALCOLOR(@"#e4e4e4");
                [cell addSubview:line];
            }
            
            NSArray *noteArr = @[@"商品总价",@"运费"];
            NSString *price = @"";
            NSString *freight = @"";
            if (_model) {
                price = [NSString stringWithFormat:@"¥%@",_model.proPrice];
                freight = [NSString stringWithFormat:@"¥%@",_model.freight];
            }
            NSArray *valueArr = @[price,freight];
            for (int i = 0; i < noteArr.count; i++) {
                UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(15) + i * ScreenX375(46), ScreenX375(150), ScreenX375(16))];
                noteLabel.text = noteArr[i];
                noteLabel.textColor = REXADECIMALCOLOR(@"#333333");
                noteLabel.font = Kfont(14);
                [cell addSubview:noteLabel];
                
                UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(166), ScreenX375(15) + i * ScreenX375(46), ScreenX375(150), ScreenX375(16))];
                valueLabel.text = valueArr[i];
                valueLabel.textColor = REXADECIMALCOLOR(@"#333333");
                valueLabel.font = Kfont(14);
                valueLabel.textAlignment = NSTextAlignmentRight;
                [cell addSubview:valueLabel];
            }

            UILabel *allLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(266), ScreenX375(105), ScreenX375(250), ScreenX375(22))];
            allLabel.textColor = REXADECIMALCOLOR(@"#ff001f");
            NSString *moneyStr = @"实付款:￥0.00";
            if (_model.payPrice) {
                moneyStr = [NSString stringWithFormat:@"实付款:￥%@",_model.payPrice];
            }
            NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:moneyStr];
            [attributedStr addAttribute:NSForegroundColorAttributeName value:REXADECIMALCOLOR(@"#333333") range:NSMakeRange(0, 4)];
            allLabel.attributedText = attributedStr;
            
            allLabel.font = Kfont(18);
            allLabel.textAlignment = NSTextAlignmentRight;
            [cell addSubview:allLabel];
            return cell;
        }
    }else if (indexPath.section == 2) {
        static NSString *cellId = @"priceCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        for (UIView *subView in cell.subviews) {
            [subView removeFromSuperview];
        }
        UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(18), ScreenX375(250), ScreenX375(15))];
        numLabel.tag = 105;
        if (_model) {
            numLabel.text = [NSString stringWithFormat:@"订单编号：%@",_model.ordNum];
        }
        numLabel.textColor = REXADECIMALCOLOR(@"#999999");
        numLabel.font = Kfont(13);
        [cell addSubview:numLabel];
        
        UIButton *copyBtn =[[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(300), ScreenX375(16), ScreenX375(57), ScreenX375(21))];
        [copyBtn setTitle:@"复制" forState:UIControlStateNormal];
        [copyBtn setTitleColor:REXADECIMALCOLOR(@"#666666") forState:UIControlStateNormal];
        copyBtn.titleLabel.font = Kfont(12);
        [copyBtn addTarget:self action:@selector(copyClicked) forControlEvents:UIControlEventTouchUpInside];
        copyBtn.layer.cornerRadius = ScreenX375(4);
        copyBtn.clipsToBounds = YES;
        copyBtn.layer.borderWidth = 0.5;
        copyBtn.layer.borderColor = REXADECIMALCOLOR(@"#999999").CGColor;
        [cell addSubview:copyBtn];
        
        
        UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(43), ScreenX375(250), ScreenX375(15))];
        if (_model) {
            timeLabel.text = [NSString stringWithFormat:@"下单时间：%@",[HttpManager TimeStamp:_model.createTime]];
        }
        timeLabel.textColor = REXADECIMALCOLOR(@"#999999");
        timeLabel.font = Kfont(13);
        [cell addSubview:timeLabel];
        
        if ([_status integerValue] > 0) {
            UILabel *payTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(68), ScreenX375(250), ScreenX375(15))];
            if (_model) {
                payTimeLabel.text = [NSString stringWithFormat:@"付款时间：%@",[HttpManager TimeStamp:_model.payTime]];
            }
            payTimeLabel.textColor = REXADECIMALCOLOR(@"#999999");
            payTimeLabel.font = Kfont(13);
            [cell addSubview:payTimeLabel];
        }
        
        return cell;
    }else {
        static NSString *cellId = @"operateCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return ScreenX375(60);
        }
        if ([_status integerValue] >= 1 && [_model.status integerValue] && _model.recName) {
            return ScreenX375(85);
        }
        return 0;
    }else if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            return ScreenX375(49);
        }else if (indexPath.row == 1) {
            return ScreenX375(105);
        }
        return ScreenX375(139);
    }else if (indexPath.section == 2) {
        if ([_status integerValue] == 0) {
            return ScreenX375(75);
        }
        return ScreenX375(98);
    }
    return ScreenX375(49);
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return ScreenX375(10);
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = RGB_COLOR(244, 244, 244);
    return view;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)copyClicked{
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = _model.ordNum;
    [HttpManager showNoteMsg:@"复制成功"];
}

@end
